// $codepro.audit.disable numericLiterals, variableShouldBeFinal
/* Copyright (c) 2011 Team A CS2340. All rights reserved.*/

package edu.gatech.teama.doctorsoffice.client.view;

import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.SwingConstants;

import edu.gatech.teama.doctorsoffice.client.presenter.AppointmentInfoPresenter;
import edu.gatech.teama.doctorsoffice.client.presenter.ServerConnection;
import edu.gatech.teama.doctorsoffice.model.Appointment;
import edu.gatech.teama.doctorsoffice.model.Patient;

import edu.gatech.teama.doctorsoffice.model.User;
import net.miginfocom.swing.MigLayout;

import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextArea;

/**
 * AppointmentInfoPanel.java
 * @author unknown
 * @version 1.0
 */
public class AppointmentInfoPanel extends JPanel {

	/** an appointment info preseneter */
	private AppointmentInfoPresenter myPresenter;
	
	/** a current appointment*/
	private Appointment appointment; // $codepro.audit.disable variableShouldBeFinal
	
	/**
	 * Create the panel.
	 *
	 * @param appointment the appointment
	 */
	public AppointmentInfoPanel(Appointment appointment) { // $codepro.audit.disable com.instantiations.assist.eclipse.analysis.audit.rule.effectivejava.constructorsOnlyInvokeFinalMethods
		myPresenter = new AppointmentInfoPresenter(appointment);
		final ServerConnection sc = ServerConnection.getInstance();
		
		this.appointment = appointment;
		
		setLayout(new MigLayout("", "[161px,grow][215px,grow]", 
				"[23px][14px][23px][23px][grow]"));
		
		JButton btnBackToLookup = new JButton("Back To Lookup");
		btnBackToLookup.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				MainWindow.backToMainPanel();
			}
		});
		add(btnBackToLookup, "cell 0 0,alignx left,aligny top");
		
		JLabel label = new JLabel("<<Patient Name>>");
		User patient = sc.getUser(appointment.getPatientUsername());
		label.setText(patient.getFirstName() + " " + patient.getLastName());
		label.setHorizontalAlignment(SwingConstants.CENTER);
		add(label, "cell 0 1,growx,aligny top");
		
		JButton btnViewPatientInformation = new JButton("View Patient Information");
		add(btnViewPatientInformation, "cell 0 2,alignx right,aligny top");
		
		JButton btnViewPatientHistory = new JButton("View Patient History");
		add(btnViewPatientHistory, "cell 0 3,growx,aligny top");
		
		JLabel label_1 = new JLabel("<<Appointment Date/Time>>");
		label_1.setText(appointment.getDate().toString("MM/dd/yyyy HH:mm"));
		label_1.setHorizontalAlignment(SwingConstants.CENTER);
		add(label_1, "cell 1 1,growx,aligny top");
		
		JButton btnTreatmentRecord = new JButton("Open Treatment Record");
		btnTreatmentRecord.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				myPresenter.openTreatmentRecordDialog();
			}
		});
		add(btnTreatmentRecord, "cell 1 2,growx,aligny top");
		
		JTextArea textArea = new JTextArea();
		textArea.setEditable(false);
		textArea.setText(appointment.getReason());
		add(textArea, "cell 0 4,grow");
		System.out.println(appointment.getPatientUsername());
		JPanel historyPanel = 
			new MedicalHistoryReportPanel((Patient) sc.getUser(
					appointment.getPatientUsername()));
		add(historyPanel, "cell 1 4,grow");

		this.setMinimumSize(new Dimension(1024, 800));
	}
}
